﻿<!--#include file="include/config.asp"-->
<!--#include file="include/conn_f.asp"-->
<!--#include file="top.asp"-->
<!--#include file="left.asp"-->
<!--#include file="include/syscode.asp"-->
<!--#include file="ipcountry/ipcountry.asp" -->
<br />
<center>
    <%
gameCoinPriceId=request("gameCoinPriceId")
gameCoinId=saferequest("gameCoinId",1)
gameaccount=request("gameaccount")
gameCoinQuantity=request("gameCoinQuantity")
memo_cust=request("memo")
IP=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If IP="" Then
    IP=Request.ServerVariables("remote_addr")
End If
ip_address=split(IP,",",-1,1)
If UBound(ip_address)>-1 and len(ip_address(0))>7 Then
    ipcountry=IP2Country(ip_address(0))
Else
    ipcountry="CN"
End If

If Session("cust_id")="" Then
    Response.Write  "请先登录"
    Response.End
Else
    cust_id=Session("cust_id")
End If

'----------------------------------------
sql="select VIP,isactive from customer where cust_id="&cust_id
Set rs=conn.execute(sql)
Dim balance
balance=0
custom=0
If Not rs.eof Then
    ISVIP=cint(rs("VIP"))
    isactive=cint(rs("isactive"))
End If
rs.close

If gameCoinPriceId="0" THEN
    Response.Write "请选择服务器和派系"
    Response.End
End If
If gameaccount="" THEN
    Response.Write "请填写游戏角色名称"
    Response.End
End If

sql="select * from gameCoinPrice where gameCoinPriceId ="&gameCoinPriceId 
Set rs=conn.execute(sql)
If Not rs.eof Then
    salePrice=rs("salePrice")
    gameCoinDistrictId=rs("gameCoinDistrictId")
    gameCoinServerId=rs("gameCoinServerId")
    gameCoinDivId=rs("gameCoinDivId")
End If
sql="select max(gameCoinDiscount) from gamecoinquantity where gameCoinId="&gameCoinId&" and gameCoinQuantityValue<="&gameCoinQuantity
Set rs=conn.execute(sql)
If Not rs.eof Then
    discount=rs(0)
Else
    discount=0
End If
rs.close
total_amount=ccur(salePrice*gameCoinQuantity*(1-discount))
If ISVIP=1 Then
    total_amount=total_amount*0.95
End If

sql="insert into orders(cust_id,goods_type,card_1,card_1_amount,total_amount,memo_cust,order_time,IP,IPCOUNTRY)"
sql=sql&" values("&cust_id&",6,"&gameCoinId&","&gameCoinQuantity&","&total_amount&",'"&memo_cust&"',now(),'"&IP&"','"&ipcountry&"')"
conn.execute sql

sql="select LAST_INSERT_ID() from orders"
rs.open sql,conn
orders_id=rs(0)
rs.close

sql="insert into orders_detail(orders_id,goods_type,card_id,amount) values("&orders_id&",6,"&gameCoinId&","&gameCoinQuantity&")"
conn.execute sql
sql="select LAST_INSERT_ID() from orders_detail"
rs.open sql,conn
orders_detail_id=rs(0)
rs.close

sql="insert into gamecoin_detail (orders_id,orders_detail_id,gameCoinId,gameCoinPriceId,gameCoinQuantity,gameaccount) values("&orders_id&","&orders_detail_id&","&gameCoinId&","&gameCoinPriceId&","&gameCoinQuantity&",'"&gameaccount&"')"
conn.execute sql

Response.Redirect "ckout.asp?orders_id="&orders_id

    %>
    
    <!--#include file="bottom.asp"-->
